package com.tianya.portal.file.service.impl;

import com.tianya.common.web.utils.StringUtils;
import com.tianya.portal.file.config.MinioConfig;
import com.tianya.portal.file.service.IFileService;
import io.minio.GetObjectArgs;
import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.InputStream;

@Service
public class MinioSysFileServiceImpl  implements IFileService {
    @Autowired
    private MinioConfig minioConfig;

    @Autowired
    private MinioClient client;

    @Override
    public InputStream downloadFiles(String path, String bucketName) throws Exception {
        //没有指定桶,则使用默认桶
        bucketName = StringUtils.isEmpty(bucketName) ? minioConfig.getBucketName() : bucketName;
        GetObjectArgs args = GetObjectArgs.builder()
                .bucket(bucketName)
                .object(path)
                .build();
        return client.getObject(args);
    }
}
